
# coding: utf-8

# In[3]:

import matplotlib.pyplot as plt


# In[4]:

from matplotlib import style
style.use('ggplot')
import numpy as np
from sklearn.cluster import KMeans


# In[5]:

x1=np.array([[1,2],[1.5,1.8],
            [5,8],
            [8,8],
            [1,0.8],
            [9,11]]



)



# In[6]:

plt.scatter(x1[:,0],x1[:,1],s=150)
plt.show()


# In[7]:

clf=KMeans(n_clusters=2)


# In[8]:

clf.fit(x1)


# In[13]:

centroids = clf.cluster_centers_
labels=clf.labels_
colors=['g.','r.','c.','b.','k.','o.']



# In[15]:

for i in range(len(x1)):
    plt.plot(x1[i][0],x1[i][1],colors[labels[i]],markersize = 10)
plt.scatter(centroids[:,0],centroids[:,1],marker='x',s=150,linewidths=5)
plt.show()


# In[ ]:



